//
//  MainTabBar.swift
//  Weibo
//
//  Created by 付启刚 on 15/12/12.
//  Copyright © 2015年 faq. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {
    //重写父类构造方法
    override init(frame:CGRect){
        super.init(frame:frame)
        addSubview(composeBtn)
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        addSubview(composeBtn)
    }
    //定义子控件的frame
    override func layoutSubviews() {
        super.layoutSubviews()
        let w=self.bounds.width/5//宽
        let h=self.bounds.height//高
        let rect=CGRectMake(0, 0, w, h)
        //每个控件的x值就是系数*每个控件的宽
        var index:CGFloat=0
        for subView in subviews{
            if subView .isKindOfClass(NSClassFromString("UITabBarButton")!){
            subView.frame=CGRectOffset(rect, index*w, 0)
                index += (index==1 ? 2 : 1)//当index==1时  给+图片留个位置 直接跳过第三个,从第四个算起
            }
        }
      composeBtn.frame=CGRectOffset(rect, 2*w, 0)
        
    }
    //懒加载+号图片
    lazy var composeBtn:UIButton=UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
//    {
//    let btn=UIButton()
//        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)//枚举可以使用点语法
//        btn.setBackgroundImage(UIImage(named:  "tabbar_compose_button"), forState: .Normal)
//        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState:.Highlighted)
//        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
//        btn.sizeToFit()
//        return btn
//    }()
}
